<template>
  <div>
    <a-modal
      title="选择已返厂"
      :visible="visible"
      :width="800"
      :maskClosable="false"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div>
        <a-table
          :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
          :columns="columns"
          :data-source="tableData"
          :loading="loading">
          <!-- 序号列插槽 -->
          <template slot="indexSlot" slot-scope="text, record, index">
            {{ index + 1 }}
          </template>
          <template slot="testPiece" slot-scope="text">
            {{ text==0?'否':'是' }}
          </template>
        </a-table>
      </div>
    </a-modal>
  </div>
</template>
<script>

import { warehouseReceiptItems } from '@/api/baseData/warehouseReceiptItems'
export default {
    name: 'ReturnedFactoryDialogVue',
  data () {
    return {
      ModalText: 'Content of the modal',
      visible: false,
      confirmLoading: false,
      columns: [
        {
            title: '序号',
            dataIndex: 'indexSlot',
            ellipsis: true,
            scopedSlots: { customRender: 'indexSlot' },
            width: 80
        },
        {
            title: '是否试刀件',
            dataIndex: 'testPiece',
            scopedSlots: { customRender: 'testPiece' },
            align: 'center'
        },
        {
            title: '零件号',
            dataIndex: 'partNumber'
        },
        {
            title: '铸件号',
            dataIndex: 'castingNumber'
        },
        {
            title: '零件名称',
            dataIndex: 'partName'
        }
      ],
      tableData: [],
      partDrawingNo: '',
      selectedRows: [],
      selectedRowKeys: [],
      loading: false
    }
  },
  computed: {
    // rowSelection () {
    //   return {
    //     onChange: (selectedRowKeys, selectedRows) => {
    //       console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
    //     },
    //     getCheckboxProps: record => ({
    //       props: {
    //         disabled: record.name === 'Disabled User', // Column configuration not to be checked
    //         name: record.name
    //       }
    //     })
    //   }
    // }
  },
  methods: {
    init () {
        this.loading = true
        warehouseReceiptItems({ partDrawingNo: this.partDrawingNo, status: 2 }).then(res => {
            this.tableData = res.data
            this.loading = false
        })
    },
    showModal (partDrawingNo) {
        this.partDrawingNo = partDrawingNo
        this.init()
      this.visible = true
    },
    onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
        console.info(this.selectedRowKeys, this.selectedRows)
    },
    handleOk (e) {
        this.selectedRows = this.selectedRows.map(it => { return { ...it, nametestPiece: it.testPiece, warehouseShipmentId: it.id } })
      this.$emit('selectedRows', this.selectedRows)
      this.handleCancel()
    },
    handleCancel (e) {
      this.visible = false
      this.partDrawingNo = ''
    }
  }

}
</script>
